//
//  AppDelegate.m
//  realmDB
//
//  Created by 蜂巢网络科技 on 2017/9/13.
//  Copyright © 2017年 fengchao. All rights reserved.
//

#import "AppDelegate.h"
#import "RQBook.h"
@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
   
    RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
    config.schemaVersion = 8;
    config.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion){
        // 替换属性名
//        if (oldSchemaVersion < 3) { // 重命名操作应该在调用 `enumerateObjects:` 之外完成
//            [migration renamePropertyForClass:RQBook.className oldName:@"author" newName:@"authoraaa"];
//        }
//      [migration enumerateObjects:RQBook.className block:^(RLMObject *oldObject, RLMObject *newObject) {
//            // 只有当 Realm 数据库的架构版本为 0 的时候，才添加 “fullName” 属性
//            if (oldSchemaVersion < 1) {
//                newObject[@"fullName"] = [NSString stringWithFormat:@"%@ %@", oldObject[@"firstName"], oldObject[@"lastName"]];
//            }
//            // 只有当 Realm 数据库的架构版本为 0 或者 1 的时候，才添加“email”属性
//            if (oldSchemaVersion < 1) {
//                newObject[@"createAt"] = @"";
//            }
//          
//        }];

    };
    [RLMRealmConfiguration setDefaultConfiguration:config];
    // 现在我们已经成功更新了架构版本并且提供了迁移闭包，打开旧有的 Realm 数据库会自动执行此数据迁移，然后成功进行访问
    [RLMRealm defaultRealm];
    
 
    return YES;
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}


- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


@end
